<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>新增用户</title>
    <meta name="新增用户" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>

    <!-- 引入公用JavaScript -->
    <script src="../js/app.js"></script>
    <script src="../js/jquery.min.js"></script>
</head>

<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form layui-form-pane" action="">

            <div class="layui-form-item">
                <label class="layui-form-label">旧密码</label>
                <div class="layui-input-inline">
                    <input type="text" name="old_password"
                           id="old_password"
                           lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">新密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="password"
                           id="password"
                           placeholder="请输入密码" autocomplete="off" class="layui-input">
                </div>

            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="repassword"
                           id="repassword"
                           placeholder="请输入密码" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">务必与新密码一致</div>
            </div>


            <div class="layui-form-item">
                <button class="layui-btn"   type="button" onclick="change_password()">确认修改</button>
            </div>
        </form>
    </div>
</div>
<script>
    function change_password() {
        var userInfo = app.getUserGlobalInfo();
        var managerInfo = app.getManagerGlobalInfo();
        var old_password = $('#old_password'),
            password = $('#password'),
            repassword = $('#repassword');
        console.log(password.val());
        console.log(old_password.val());
        if (password.val() != repassword.val()){
            layui.use([ 'layer'],
                function () {
                    var layer = layui.layer;
                    layer.msg('前后密码不一致！', {
                        icon: 5,
                        time: 1000
                    })

                })
        }else {
            if (userInfo != null){
                $.ajax({
                    url: app.ServerUrl + 'v1/user/changePassword/1',
                    type: "post",
                    dataType: "json",
                    async: true,
                    data: {
                        newPassWord:password.val(),
                        oldPassword:old_password.val(),
                        workId:userInfo.workId
                    },
                    success: function(data) {
                        if (data.resultStatus !== 1){
                            layer.msg(data.resultIns, {
                                icon: 5,
                                time: 1000
                            })
                        }else {
                            layer.msg("修改成功!", {
                               icon:6,
                                time: 1000
                            })
                        }
                    },
                    error: function(e) {
                        console.log(e.statusText)
                    }

                })
            }
            if (managerInfo != null){
                $.ajax({
                    url: app.ServerUrl + 'v1/user/changePassword/0',
                    type: "post",
                    dataType: "json",
                    async: true,
                    headers: {
                        "Authorization": "460bcdb0-b326-4d6d-ac99-232c83ba6d80"
                    },
                    data: {
                        newPassWord:password.val(),
                        oldPassword:old_password.val(),
                        workId:managerInfo.workId
                    },
                    success: function(data) {
                        if (data.resultStatus!=1){
                            layer.msg(data.resultIns, {
                                icon: 5,
                                time: 1000
                            })
                        }else {
                            layer.msg("修改成功!", {
                                icon: 6,
                                time: 1000
                            })
                        }
                    },
                    error: function(e) {
                        console.log(e.statusText)
                    }

                })
            }
        }
    }
</script>
<script>
    var _hmt = _hmt || [];
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>


</body>

</html>